var url;
function formatOper(val, row, index) {
	console.log(row.roleName);
	return '<a href="#" onclick="show(' + '\'' + row.roleName + '\'' + ')"'+'>详情</a>';
//	return '<a href="role_uri.jsp?roleName="' + row.roleName + '">详情</a>';
}

/**
 * 在role.jsp中查看详情
 */
function show(roleName){
	$('#dg').datagrid({
	    url:'Admin/RoleUriController/PageRoleUri?roleName=' + roleName,
	    columns:[[
	        {field:'role_id',title:'Role_id',width:100},
	        {field:'role',title:'Role',width:100},
	        {field:'uri',title:'Uri',width:100,align:'right'}
	    ]]
	});
}



function newRole() {
	$('#dlg').dialog('open').dialog('center').dialog('setTitle', 'New Role');
	$('#fm').form('clear');
	url = 'Admin/RoleController/addRole';
}


function saveRole() {
	$('#fm').form('submit', {
		url : url,
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			if (result.errorMsg) {
				$.messager.show({
					title : 'Error',
					msg : result.errorMsg
				});
			} else {
				$('#dlg').dialog('close'); // close the dialog
				$('#dg').datagrid('reload'); // reload the user data
			}
		}
	});
}
function destroyRole() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'Are you sure you want to destroy this user?', function(r) {
					if (r) {
						$.post('Admin/RoleController/deleteRole', {
							roleId : row.roleId
						}, function(result) {
							if (result.success) {
								$('#dg').datagrid('reload'); // reload the
								// user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');
					}
				});
	}
}